import router from 'vue-router';
import store from './store';
import NProgress from 'nprogress' // Progress 进度条
import 'nprogress/nprogress.css'// Progress 进度条样式

import { getToken } from '@/static/utils/auth' // 验权


const whiteList = ['/login',] // 不重定向白名单

router.beforeEach((to, from, next) => {
  NProgress.start();
  //验证是否登录
  if (getToken()){
    //用户已登录
    if (to.path === '/login') {
      next({ path: '/' });
      NProgress.done();
    }else{

    }
  }else{
    //用户未登录
    if (whiteList.indexOf(to.path) !== -1) {
      //请求地址为白名单
      next()
    } else {
      //请求地址不在白名单
      next('/login')
      NProgress.done()
    }
  }

});

router.afterEach(() => {
  NProgress.done() // 结束Progress
});


